package br.com.insight.consultoria.integracao.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import br.com.insight.consultoria.entity.Noticia;
import br.com.insight.consultoria.erro.exception.InsightException;
import br.com.insight.consultoria.integracao.dao.genericdao.GenericDAO;
import br.com.insight.consultoria.integracao.dao.interfacedao.NoticiaDAO;

public class NoticiaImpDAO extends GenericDAO implements NoticiaDAO{
	
	@Override
	public void inserir(Noticia noticia) throws InsightException {
		saveOrUpdateEntity(noticia);
	}
	
	@Override
	public void alterar(Noticia noticia) throws InsightException {
		saveOrUpdateEntity(noticia);
	}
	
	@Override
	public void excluir(Noticia noticia) throws InsightException {
		deleteEntity(noticia);
	}
	
	@Override
	public Noticia getNoticia(Long id) throws InsightException {
		return (Noticia)getEntityById(Noticia.class, id);
	}
	
	@Override
	public List<Noticia> listarCapa() throws InsightException {
		Criteria query=getSession().createCriteria(Noticia.class);
		query.addOrder(Order.desc("id"));
		query.setMaxResults(5);
		return query.list();
	}
}
